<?php

require_once getcwd().'/data.impl/UserRepository.php';
require_once getcwd().'/data.models/UserRepo.php';
require_once getcwd().'/service/IUserManager.php';
require_once getcwd().'/library/Log.php';


	class UserManager implements IUserManager {
		public $repo;
		public $model;
		
		public function __construct(){
			$this->repo = new UserRepository();
		}
		
		
		public function get($id){
			Log::write("UserManager::get");
			$repo = $this->repo;			
			$users = $repo->getObject($id);
			Log::write("fin UserManager::get");
			return $users;
		}
		
		public function insert($object){
			Log::write("UserManager::insert");
			$this->createModelRepoFromModel($object);
			$repo = $this->repo;
			$impact = $repo->insertObject($this->model);
			Log::write("value returned : ".$impact);
			Log::write("fin UserManager::insert");
			return $impact;
		}
		
		public function update($object){
			Log::write("UserManager::update");
			$uRepo = new UserRepo();
			$uRepo->CreateUserRepo($object);
			$repo = $this->repo;
			$impact = $repo->updateObject($uRepo);
			Log::write("value returned : ".$impact);
			Log::write("fin UserManager::update");
			return $impact;
		}
		
		public function delete($object){
			Log::write("UserManager::delete");
			$repo = $this->repo;
			$impact = $repo->deleteObject($object->uid);
			Log::write("value returned : ".$impact);
			Log::write("fin UserManager::delete");
			return $impact;
		}
		
		public function createModelRepoFromModel($userModel){
			$modelRepo = new UserRepo();
			$modelRepo->uid = $userModel->uid;
			$modelRepo->login = $userModel->login;
			$modelRepo->password = $userModel->access;
			$modelRepo->token = $userModel->phoneToken;
			$modelRepo->name = $userModel->name;
			
			$this->model = $modelRepo;
		}
		
		
	}